import { ref } from 'vue'
import { oaEmpSave } from '@/api/basic'

/**
 * OA账号表单服务
 */
export default function () {
  const formSaveLoading = ref(false)
  const form = ref<{
    defaultChoose: 0 | 1
    id: string
    jobNumber: string
    name: string
  }>({
    defaultChoose: 0,
    id: '',
    jobNumber: '',
    name: '',
  })

  const resetForm = () => {
    form.value = {
      defaultChoose: 0,
      id: '',
      jobNumber: '',
      name: '',
    }
  }

  const formSave = async () => {
    try {
      formSaveLoading.value = true
      const res = await oaEmpSave(form.value)
      formSaveLoading.value = false
      return res.data
    } catch (e) {
      formSaveLoading.value = false
    }
  }

  return {
    form,
    formSaveLoading,
    formSave,
    resetForm,
  }
}
